<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<title>资源列表</title>
	<meta name="renderer" content="webkit">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
	<meta name="apple-mobile-web-app-status-bar-style" content="black">
	<meta name="apple-mobile-web-app-capable" content="yes">
	<meta name="format-detection" content="telephone=no">
	<link rel="stylesheet" href="/${BasePath}/static/layui/css/layui.css" media="all" />
	<link rel="stylesheet" href="/${BasePath}/static/css/public.css" media="all" type="text/css">
</head>
<body class="childrenBody">
<form class="layui-form" lay-filter="example">
	<blockquote class="layui-elem-quote quoteBox">
			<div class="layui-inline">
				<a class="layui-btn layui-btn-normal addPermission">添加资源</a>
			</div>
<!-- 			<div class="layui-inline">
				<a class="layui-btn layui-btn-danger layui-btn-normal delAll_btn">批量删除</a>
			</div> -->
	</blockquote>
	<div id="menuTree"></div>
</form>
<script type="text/javascript" src="/${BasePath}/static/js/common/jquery-2.1.0.min.js"></script>
<script src="/${BasePath}/static/layui/layui.js" charset="utf-8" type="text/javascript"></script>

<script type="text/javascript">
var datass;
$(document).ready(function(){ 
	$.ajax({
		type: 'post',
		url: "/${BasePath}/power/getMem",
		dataType: 'json',
		async:false, 
		success: function(data){
			datass = data;
		}
	});	
}); 
$(".addPermission").click(function(){
	window.location.href="/${BasePath}/power/addPermission"; 
})


  function select(nodeId) {
    console.info(nodeId);
    alert(nodeId)
  }
  function del(nodeId) {
      layer.confirm('确定删除?', function(){
          delMenu(nodeId);
      });
  }
  function update(nodeId){
      console.log(nodeId);
      window.location.href="/${BasePath}/power/addPermission?id="+nodeId; 
  }

  var layout = [
    { name: '资源名称', treeNodes: true, headerClass: 'value_col', colClass: 'value_col', style: 'width: 15%'
    },
    { name: 'url',headerClass: 'value_col', colClass: 'value_col', style: 'width: 10%',
      render: function(row) {
        return '<div class="layui-table-cell laytable-cell-1-username">'+(typeof(row.url)=="undefined"?'':row.url)+'</div>'; //列渲染
      }
    }, { name: '类型',headerClass: 'value_col', colClass: 'value_col', style: 'width: 10%',
      render: function(row) {
        return '<div class="layui-table-cell laytable-cell-1-username">'+(row.menuType=="3"?'按钮':'菜单')+'</div>'; //列渲染
      }
    },{ name: '图标',headerClass: 'value_col', colClass: 'value_col', style: 'width: 5%',
      render: function(row) {
        return '<div class="layui-table-cell laytable-cell-1-username"><i class="layui-icon">'+(typeof(row.icon)=="undefined"?'':row.icon)+'</i></div>'; //列渲染
      }
    },{ name: '序号',headerClass: 'value_col', colClass: 'value_col', style: 'width: 5%',
          render: function(row) {
              return '<div class="layui-table-cell laytable-cell-1-username"><i class="layui-icon">'+(typeof(row.orderNum)=="undefined"?'':row.orderNum)+'</i></div>'; //列渲染
          }
      },

    {
      name: '操作',
      headerClass: 'value_col',
      colClass: 'value_col',
      style: 'width: 20%',
      render: function(row) {
    	  if(row.children!=null){
    		  var chil_len=row.children.length;
    	  }else{
    		  chil_len=0
    	  }
        var str= '<a class="layui-btn layui-btn-primary layui-btn-xs" onclick="select(\'' + row.id + '\')"><i class="layui-icon">&#xe615;</i> 查看</a>' +
            '<a class="layui-btn layui-btn-xs  layui-btn-normal" onclick="update(\'' + row.id + '\')"><i class="layui-icon">&#xe642;</i> 编辑</a>'; //列渲染
        if(chil_len==0){
          str+='<a class="layui-btn layui-btn-danger layui-btn-xs" onclick="del(\'' + row.id + '\')"><i class="layui-icon">&#xe640;</i> 删除</a>';
        }
        return str;
      }
    },
  ];
  layui.use(['tree', 'layer'], function() {
    var layer = layui.layer;
    
        layui.treeGird({
            elem: '#menuTree',
            nodes:datass,
            layout: layout
          });


    var $ = layui.$, active = {
        add: function () {
            add('添加菜单', 'showAddMenu', 700, 550);
        }
    }
    $('.layui-btn-group .layui-btn').on('click', function () {
        var type = $(this).data('type');
        active[type] ? active[type].call(this) : '';
    });
  });
  function add(title, url, w, h) {
      if (title == null || title == '') {
          title = false;
      }
      ;
      if (url == null || url == '') {
          url = "/error/404";
      }
      ;
      if (w == null || w == '') {
          w = ($(window).width() * 0.9);
      }
      ;
      if (h == null || h == '') {
          h = ($(window).height() - 50);
      }
      ;
      layer.open({
          id: 'user-add',
          type: 2,
          area: [w + 'px', h + 'px'],
          fix: false,
          maxmin: true,
          shadeClose: false,
          shade: 0.4,
          title: title,
          content: url
      });
  }
  function delMenu(id) {
      $.ajax({
          url: "/${BasePath}/power/deletePermission",
          type: "post",
          data: {id: id},
          success: function (d) {
              if(d.code==="1"){
                  location.replace(location.href);
                  parent.layer.msg(d.msg,{icon:6,offset: 'rb',area:['120px','80px'],anim:2});
              }else{
                  parent.layer.msg(d.msg,{icon:5,offset: 'rb',area:['120px','80px'],anim:2});
              }
          }
      });
  }
</script>

</body>
</html>